package com.ads.tpgrupo4.domain.cpr.core;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;

import com.ads.tpgrupo4.domain.cpr.condicionesDeVentaAClientes.CondicionDeVentaAplicadaACliente;

@Entity
public class Cliente extends PersistentObject {

	private static final long serialVersionUID = 1L;
	
	private Status status;
	
	private String idOdv;
	
	@Column(unique=true)
	private String cuil;
	
	private String razonSocial;
	
	private Boolean ivaExento;
	
	@OneToMany(cascade = {CascadeType.ALL} )
	private List<CondicionDeVentaAplicadaACliente> condicionesDeVentaAsociadas;
	
	public Cliente() {
		this.ivaExento = false;
	}
	
	public String getCuil() {
		return cuil;
	}

	public void setCuil(String cuil) {
		this.cuil = cuil;
	}

	public String getRazonSocial() {
		return razonSocial;
	}

	public void setRazonSocial(String razonSocial) {
		this.razonSocial = razonSocial;
	}

	public Boolean getIvaExento() {
		return ivaExento;
	}

	public void setIvaExento(Boolean ivaExento) {
		this.ivaExento = ivaExento;
	}

	public String getIdOdv() {
		return idOdv;
	}

	public void setIdOdv(String idOdv) {
		this.idOdv = idOdv;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public List<CondicionDeVentaAplicadaACliente> getCondicionesDeVentaAsociadas() {
		return condicionesDeVentaAsociadas;
	}

	public void setCondicionesDeVentaAsociadas(
			List<CondicionDeVentaAplicadaACliente> condicionesDeVentaAsociadas) {
		this.condicionesDeVentaAsociadas = condicionesDeVentaAsociadas;
	}
	
	@Override
	public boolean equals(Object obj) {

		return cuil.equals(((Cliente)obj).getCuil());
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime
				* result
				+ ((condicionesDeVentaAsociadas == null) ? 0
						: condicionesDeVentaAsociadas.hashCode());
		result = prime * result + ((cuil == null) ? 0 : cuil.hashCode());
		result = prime * result + ((idOdv == null) ? 0 : idOdv.hashCode());
		result = prime * result
				+ ((ivaExento == null) ? 0 : ivaExento.hashCode());
		result = prime * result
				+ ((razonSocial == null) ? 0 : razonSocial.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		return result;
	}
	
}
